﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dos.ORM;
using Model;

namespace JFLogic.Logic.JFSession
{
    public class JFSessionLogic
    {
        public int Insert(TB_JFSession_Cache jfsession)
        {
            if (!Exist(jfsession.Phone))
            {
                return DB.Context.Insert<TB_JFSession_Cache>(jfsession);    
            }
            return 0;
            
        }

        /// <summary>
        /// 获取该号码是否曾经登录
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        public bool Exist(string phone)
        {
            return DB.Context.Exists<TB_JFSession_Cache>(d => d.Phone == phone);
            
        }

        public string GetJFSessionId(string phone)
        {
            object obj = DB.Context.From<TB_JFSession_Cache>()
                .Select(d => new { d.JFSessionId })
                .Where(d => (d.Phone == phone))
                .ToScalar();
            if(obj==null)
            {
                return "";
            }
            else
            {
                return obj.ToString();
            }
                
                
        }
    }
}
